package com.bluepixel.tvitalia;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.bugsense.trace.BugSenseHandler;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;

public class SplashActivity extends Activity {

    // private static final String APP_ID="BE288-F3E5B";
    // private static final String SENDER_ID="598943288799";
    private static final String BUGSENSE_APIKEY="211ef792";
    private static final String PARSE_APP_ID="vcdLeWQPmtjmtOJqIEAdu7g5T3VTfGG4yZNL0dK0";
    private static final String PARSE_CLIENT_KEY="Ud6442UDRiRAGJq503A7WDYZS359Bqa2kuGpMaKs";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// Bugsense init
	BugSenseHandler.initAndStartSession(getApplicationContext(), BUGSENSE_APIKEY);

	// Parse init
	Parse.initialize(this, PARSE_APP_ID, PARSE_CLIENT_KEY);
	PushService.setDefaultPushCallback(this, SplashActivity.class);
	ParseInstallation.getCurrentInstallation().saveInBackground();
	ParseAnalytics.trackAppOpened(getIntent());

	// Set layout
	setContentView(R.layout.activity_splash);

	final int welcomeScreenDisplay=1000;

	Thread welcomeThread=new Thread() {
	    int wait=0;

	    @Override
	    public void run() {
		try {
		    super.run();
		    while (wait < welcomeScreenDisplay) {
			sleep(100);
			wait+=100;
		    }
		}
		catch (Exception e) {
		    startActivity(new Intent(SplashActivity.this, CategoryListActivity.class));
		    finish();
		}
		finally {
		    startActivity(new Intent(SplashActivity.this, CategoryListActivity.class));
		    finish();
		}
	    }
	};
	welcomeThread.start();
    }
}
